<?php

if(!function_exists("_postValueWithTimeOut")){
    function _postValueWithTimeOut($url, $msg, $timeout = 150) {
        $result = array();
        $data = '';
        $errno = 0;
        $error = '';

        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PORT, 80);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 150);

        //execute post
        $data = curl_exec($ch);
        $errno = curl_errno($ch);
        $error = curl_error($ch);

        if ($errno > 0)
            $result[7] = 'null';
        else
            $result[7] = $data;
        //close connection
        curl_close($ch);

        return $result[7];
    }
}

if(!function_exists("_debug")){
    function _debug($var, $exit = true){
        $str = "<pre>".print_r($var, true)."</pre>";
        
        if($exit){
            exit($str);
        } else {
            echo $str;
        }
    }
}

if(!function_exists("_get_raw_object")){
    function _get_raw_object($object, $property){
        if(property_exists($object, $property)){
            return $object->$property;
        }
        
        return "";
    }
}

if(!function_exists("_str_trim")){
    function _str_trim($str, $max_length = 50){
        if(strlen($str) > $max_length){
            $str = substr($str, 0, $max_length) . "...";
        }
        
        return $str;
    }
}

